<template include="./view/htm/my.template.htm">
	<slot name="my_body">
		<?php if ($verified_check == -2) {?>
		<div class="col-lg-6 mx-auto">
			<form action="<?php echo url('my-verified');?>" enctype="multipart/form-data" method="post" id="form">

				<div class="form-group input-group">
					<input type="text" class="form-control" id="name" name="name" placeholder="姓名" required="">
					<div class="invalid-feedback"></div>
				</div>

				<div class="form-group input-group">
					<input type="value" class="form-control" id="cardid" name="cardid" placeholder="身份证号码" required="">
					<div class="invalid-feedback"></div>
				</div>

				<div class="progress mt-2">
					<div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100" style="width: 0%"  id="vcard_cp_progress"></div>
				</div>
				<div class="form-group custom-file mb-2">
					<input type="file" id="vcard_cp" name="vcard_cp" accept="image/gif,image/jpeg,image/png,image/jpg,image/bmp"  class="upload custom-file-input"/>
					<label class="custom-file-label" for="vcard_cp">选择文件</label>
				</div>
				<div class="form-group">
					<img src="" class="vcard_cp_img" />
				</div>

				<div class="progress mt-2">
					<div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100" style="width: 0%"  id="vcard_cn_progress"></div>
				</div>

				<div class="form-group custom-file mb-2">
					<input type="file" id="vcard_cn" name="vcard_cn" accept="image/gif,image/jpeg,image/png,image/jpg,image/bmp"  class="upload custom-file-input"/>
					<label class="custom-file-label" for="vcard_cn">选择文件</label>
				</div>

				<div class="form-group">
					<img src="" class="vcard_cn_img" />
				</div>

				<div class="progress mt-2">
					<div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100" style="width: 0%"  id="vcard_b_progress"></div>
				</div>

				<div class="form-group custom-file mb-2">
					<input type="file" id="vcard_b" name="vcard_b" accept="image/gif,image/jpeg,image/png,image/jpg,image/bmp"  class="upload custom-file-input" value="名片"/>
					<label class="custom-file-label" for="vcard_b">选择文件</label>
				</div>

				<div class="form-group">
					<img src="" class="vcard_b_img" />
				</div>

				<div class="form-group input-group">
					<div class="input-group-prepend">
						<span class="input-group-text"><i class="icon-lock"></i></span>
					</div>
					<input type="password" class="form-control" id="password" name="password" placeholder="输入密码" required="">
					<div class="invalid-feedback"></div>
				</div>

				<div>
					<button type="submit" class="btn btn-primary btn-block" id="submit" data-loading-text="<?php echo lang('submiting');?>...">提交审核</button>
				</div>
			</form>
		</div>
	<?php } elseif($verified_check == 0) {?>
		<div class="col-lg-6 mx-auto">
			<p>你已经成功提交实名了，请等待审核</p>
		</div>
	<?php } elseif($verified_check == -1) {?>
		<div class="col-lg-6 mx-auto">
			<p>你的实名请求被拒绝了，请点击下方按钮重新提交</p>
		</div>
	<?php } elseif($verified_check == 1) {?>
		<div class="col-lg-6 mx-auto">
			<p>你已经成功实名了。</p>
		</div>
	<?php } ?>
	</slot>
</template>

<script>
$('a[data-active="my"]').addClass('active');
$('a[data-active="my-verified"]').addClass('active');
</script>

<script>

var jform = $('#form');
var jsubmit = $('#submit');
var jupload = $('.upload');
var vcard = {};

jform.on('submit', function() {
	jform.reset();
	jsubmit.button('loading');
	var postdata = jform.serializeObject();
	postdata['cpurl'] = vcard['vcard_cp'];
	postdata['cnurl'] = vcard['vcard_cn'];
	postdata['bcurl'] = vcard['vcard_b'];
	$.xpost(jform.attr('action'), postdata, function(code, message) {
		if(code == 0) {
			$.alert(message);
			jsubmit.button(message).delay(3000).button('reset');
		} else if(xn.is_number(code)) {
			alert(message);
			jsubmit.button('reset');
		} else {
			jform.find('[name="'+code+'"]').alert(message).focus();
			jsubmit.button('reset');
		}
	});
	return false;
});

jupload.on('change', function(e){
	var load = $(this);
	var files = xn.get_files_from_event(e);
	var jprogress = $("#"+load.attr('id')+"_progress");
	var jimg = $("."+load.attr('id')+"_img");

	xn.upload_file(
		files[0], 
		xn.url('my-upload_verified-'+load.attr('id')), 
		{filetype: 'jpg'}, 
		function(code, message) {
			if(code == 0) {
				console.log(message.url);
				jimg.attr('src', message.url);
				vcard[load.attr("id")] = message.url;
				$.alert('成功');
				jprogress.delay(1000).hide();
			} else {
				$.alert(message);
			}
		}, 
		function(percent) {
			jprogress.show();
			jprogress.width(percent+'%');
		}
	);
})
</script>